home *** CD-ROM | disk | FTP | other *** search
- /*--------------------------------------------------------------------------*/
- /* The Opus Computer-Based Conversation System */
- /* (c) Copyright 1987, Wynn Wagner III, All Rights Reserved */
- /* */
- /* YOOHOO is a trademark of Wynn Wagner III */
- /* */
- /* YOOHOO-YOOHOO/2U2 is */
- /* Copyright 1987, Wynn Wagner III, All Rights Reserved */
- /* */
- /* */
- /* BinkleyTerm File Request Processor */
- /* */
- /* */
- /* This module is a very simple FOSSIL-based terminal emulator. It is */
- /* provided for your information only. You will find routines that need */
- /* to be coded and identifiers to be resolved. It has been previously */
- /* known as "OpusLink" and "OConnect". The use of the name "BinkleyTerm" */
- /* does not preclude the possibility that another "OpusLink" or "OConnect" */
- /* could be released. */
- /* */
- /* There is absolutely no guarantee that anything here will work. If you */
- /* break this routine, you own both pieces. */
- /* */
- /* USAGE: You may use this material in any program with no obligation */
- /* as long as there is no charge for your program. For more */
- /* information about commercial use, contact the "OPUSinfo HERE" */
- /* BBS (124/111). */
- /* */
- /* */
- /*--------------------------------------------------------------------------*/
-
- #include <signal.h>
- #include <ctype.h>
- #include <conio.h>
-
- #define WAZOO_SECTION
- #include "zmodem.h"
-
- #include "com.h"
-
-
- static int prep_match( template, buffer )
- char *template;
- char *buffer;
- begin
- register int i,delim;
- register char *sptr;
- int start;
-
- memset( buffer, 0, 11 );
-
- i = strlen(template);
- sptr = template;
-
-
- for(start=i=0; sptr[i]; i++)
- if ((sptr[i]=='\\') or (sptr[i]==':'))
- start = i+1;
-
- if (start) sptr += start;
- delim = 8; /* last column for ? */
-
- strupr(sptr);
-
- for(i=0; *sptr && i < 12; sptr++)
- switch(*sptr)
- begin
-
- default : buffer[i++] = *sptr;
- break;
-
- case '.' : if (i>8) return(-1);
- while(i<8)
- begin
- buffer[i++] = ' ';
- end
- buffer[i++] = *sptr;
- delim = 12;
- break;
-
- case '*' : while(i<delim)
- begin
- buffer[i++] = '?';
- end
- break;
-
- end /* switch */
- while(i<12)
- begin
- if (i == 8)
- buffer[i++] = '.';
- else
- buffer[i++] = ' ';
- end
- buffer[i] = '\0';
-
- return 0;
-
-
- end
-
-
-
-
- static int match (s1, s2 )
- char *s1, *s2;
- begin
- register char *i,*j;
-
- i = s1;
- j = s2;
-
- /* cprintf("TRYING `%s' `%s'\r\n", s1, s2 ); */
-
- while(*i)
- begin
- if ((*j != '?') and (*i != *j))
- begin
- /* cprintf("%c != %c\r\n", *i, *j ); */
- return 1;
- end
- /* else cprintf("%c == %c\r\n",*i, *j ); */
- i++;
- j++;
- end
-
- return 0;
-
- end
-
-
-
-
-
-
-
-
-
-
- /*--------------------------------------------------------------------------*/
- /* Process file requests from the remote system. The filespec requested is */
- /* turned into a local filespec if possible, then returned to either the */
- /* WaZOO or SEAdog file request logic. */
- /*--------------------------------------------------------------------------*/
-
- char *n_frproc(request, recno, updreq)
- char *request;
- int *recno;
- int updreq;
- begin
- register int i, j;
- static char s[80];
- char s1[80];
- FILE *approved;
- struct FILEINFO dta;
- char *sptr;
-
- char *their_pwd;
- char required_pwd[10];
- char *after_pwd;
-
- char our_wildcard[15];
- char their_wildcard[15];
- char magic[15];
-
- approved = NULL;
- their_pwd = NULL;
- after_pwd = NULL;
- strcpy (s1, request);
-
- /*--------------------------------------------------------------------*/
- /* Fix up the file name */
- /*--------------------------------------------------------------------*/
- for(i=0; request[i]; i++)
- if ((request[i]==' ') or (request[i]==0x09))
- begin
- request[i] = '\0';
- if (request[i+1]=='!')
- begin
- their_pwd = request+i+2;
- if (strlen(their_pwd)>6) their_pwd[6] = '\0';
- fancy_str(their_pwd);
- end
- end
- else if (request[i]<=' ') request[i] = '\0';
-
- if (!request[0]) return NULL;
-
- if (their_pwd)
- begin
- for(i=0; their_pwd[i]; i++)
- if (their_pwd[i] <= ' ') their_pwd[i] = '\0';
- end
-
-
- /*--------------------------------------------------------------------*/
- /* Initialization(s) */
- /*--------------------------------------------------------------------*/
- i =
- errno = 0;
- sptr = NULL;
-
- strupr(request);
- if (*recno == -1)
- status_line("*%s request (%s)", updreq?"Update":"File", request);
-
-
- /*--------------------------------------------------------------------*/
- /* Reserved words */
- /*--------------------------------------------------------------------*/
- if (*recno < 0)
- {
- if (!strcmp(request,"FILES"))
- begin
- if (ctl.avail_list)
- strcpy(s,ctl.avail_list);
- else
- begin
- s[0] = '\0';
- sptr = "No AVAIL list";
- end
- goto avail;
- end
-
- else if (!strcmp(request,"ABOUT"))
- begin
- s[0] = '\0';
- goto avail;
- end
- }
-
- prep_match( request, their_wildcard );
-
-
- /*--------------------------------------------------------------------*/
- /* See if the file is approved for transmission */
- /*--------------------------------------------------------------------*/
- approved = fopen(ctl.request_list,read_ascii);
- if (got_error(OPEN_msg,ctl.request_list)) goto err;
-
- j = -1;
- magic[0] = '\0';
- while(!feof(approved))
- begin
- /* If we had a magic name, copy back the old wildcard stuff */
- if (magic[0])
- {
- strcpy (their_wildcard, magic);
- magic[0] = '\0';
- }
-
- s[0] =
- required_pwd[0] = '\0';
-
- fgets(s,78,approved);
-
- for(i=0; s[i]; i++)
- if (s[i]==0x09) s[i] = ' ';
- else if (s[i]<' ') s[i] = '\0';
-
- if (!s[0]) continue;
-
- /*--------------------------------------------------------------*/
- /* Check for transaction-level password */
- /*--------------------------------------------------------------*/
- for(i=0; s[i]; i++)
- begin
- if (s[i]==' ')
- begin
- s[i] = '\0';
- if (s[i+1]=='!')
- begin
- strncpy( required_pwd, s+i+2, 8 );
- if (strlen(required_pwd)>6) required_pwd[6] = '\0';
-
- after_pwd = s+i+1;
- while (*after_pwd && (!isspace (*after_pwd)))
- ++after_pwd;
-
- if (*after_pwd)
- ++after_pwd;
-
- for(i=0; required_pwd[i]; i++)
- if (required_pwd[i]<=' ') required_pwd[i] = '\0';
-
- break;
- end
- else
- begin
- after_pwd = s+i+1;
- end
- end
- else if (s[i]<' ') s[i]=0;
- end
-
-
- if (!s[0]) continue;
-
- if ((s[0] == '$') || (s[0] == ';'))
- continue;
-
- if (s[0] == '@')
- {
- /* Magic name */
- if (stricmp (&(s[1]), request) == 0)
- {
- /* It matches */
- strcpy (magic, their_wildcard);
- strcpy (s, after_pwd);
- strcpy (their_wildcard, "????????.???");
- }
- else
- {
- /* It doesn't match, so go on */
- continue;
- }
- }
-
- if (!dfind(&dta,s,0))
- begin
- do
- begin
- prep_match(dta.name,our_wildcard);
-
- if (!match(our_wildcard,their_wildcard))
- begin
- for(i=strlen(s);i;i--)
- if (s[i]=='\\')
- begin
- s[i+1]=0;
- break;
- end
- strcat(s,dta.name);
-
- if (required_pwd[0])
- begin
- fancy_str(required_pwd);
- if ( (strcmp(required_pwd,their_pwd)) and
- (strcmp(required_pwd,remote_password))
- )
- begin
- status_line("!Transaction pwd err: %s %s %s",
- required_pwd,
- their_pwd,
- remote_password
- );
- end
- else
- {
- if (++j > *recno)
- goto gotfile;
- }
- end
- else
- {
- if (++j > *recno)
- goto gotfile;
- }
- end
- end
- while(!dfind(&dta));
-
- end /* if dfind */
-
- else status_line("!OKFILE ERR `%s'",s);
-
- s[0] = '\0';
-
- end /* while not eof(approved) */
-
-
-
- /*--------------------------------------------------------------------*/
- /* File requested not found, send the system ABOUT file. */
- /*--------------------------------------------------------------------*/
- avail:
- strcpy (request, s1);
-
- if (*recno > -1)
- {
- *recno = -1;
- return (NULL);
- }
- if (!s[0])
- begin
- *recno = -1;
- if (ctl.freq_about)
- strcpy(s,ctl.freq_about);
- else
- begin
- sptr = "No ABOUT file";
- goto err;
- end
- end
-
- /*--------------------------------------------------------------------*/
- /* Send a file */
- /*--------------------------------------------------------------------*/
- gotfile:
- strcpy (request, s1);
-
- ++(*recno);
- if (approved) fclose(approved);
- errno = 0;
- fancy_str(s);
- return s;
-
-
- /*--------------------------------------------------------------------*/
- /* Error return */
- /*--------------------------------------------------------------------*/
- err:
- strcpy (request, s1);
-
- *recno = -1;
- if (sptr) status_line("!%s Request Err: %s", updreq?"Update":"File", sptr);
- return NULL;
-
- end